const { MongoClient } = require('mongodb');

// 替换为你的 MongoDB 连接字符串
const uri = 'mongodb+srv://zzycbb:<db_password>@cluster0.hlydq.mongodb.net/?retryWrites=true&w=majority&appName=Cluster0'; 
const client = new MongoClient(uri);

async function connectToDatabase() {
    try {
        await client.connect();
        console.log('成功连接到 MongoDB 数据库');
        return client.db('yourDatabaseName'); 
    } catch (error) {
        console.error('连接数据库时出错:', error);
        throw error;
    }
}

module.exports = { connectToDatabase };
